package com.gt.web.srv.web.api.ss;

import com.github.pagehelper.PageInfo;
import com.gt.web.api.common.R;
import com.gt.web.srv.service.ActivityGroupService;
import com.gt.web.srv.web.api.command.ActivityGroupCommand;
import com.gt.web.srv.web.api.resource.ss.ActivityGroupResource;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


@Slf4j
@RestController
@RequestMapping("/ssActivityGroup/")
@Api(tags = "参赛接口")
public class ActivityGroupController {

    @Autowired
    private ActivityGroupService service;

    @ApiOperation(value = "保存参赛者信息（新增或更新）", notes = "保存参赛者信息（新增或更新）",position = 1)
    @PostMapping("save")
    public R save(@RequestHeader("token") String token, @Validated @RequestBody ActivityGroupCommand cmd) {
        service.save(cmd);
        return R.OK;
    }

    @ApiOperation(value = "根据ID查询详情", notes = "根据ID查询详情",position = 2)
    @GetMapping("selectById")
    public R selectById(@RequestHeader("token") String token, @RequestParam(name = "activityGroupId") Long activityGroupId) {
        return R.ok(service.getById(activityGroupId));
    }

    @ApiOperation(value = "分页查询", notes = "分页查询",position = 3)
    @PostMapping("page")
    public R<PageInfo<ActivityGroupResource>> page(@RequestHeader("token") String token, @Validated @RequestBody ActivityGroupCommand cmd) {
        return R.ok(service.page(cmd));
    }

    @ApiOperation(value = "更新状态", notes = "更新状态",position = 4)
    @PostMapping("updateStatus")
    public R updateStatus(@RequestHeader("token") String token, @RequestParam(name = "activityGroupId") Long activityGroupId,
                                                    @RequestParam(name = "status") Integer status) {

        return R.ok(service.updateStatus(activityGroupId, status));
    }


}
